package com.mastercard.labs

class VoucherService {

    def serviceMethod() {

    }
	
	def searchByCondition(searchTitle, searchCountry, searchMerchant, searchCategory, searchDate){
		def result = Voucher.createCriteria().list {
			log.info 'searchByCondition: searchTitle('+searchTitle+')searchCountry('+searchCountry+')searchMerchant('+searchMerchant+')searchCategory('+searchCategory+')searchDate('+searchDate+')'
			if(searchTitle)
				ilike("title", "%" + searchTitle + "%")
			if(searchCountry) {
					country {
					eq("id", searchCountry as Long)
				}
			}
			if(searchMerchant) {
					merchant {
					eq("id", searchMerchant as Long)
				}
			}
			if(searchCategory) {
					categories {
						eq("id", searchCategory as Long)
				}
			}
			if(searchDate) {
					lt("startDate", searchDate)
					gt("endDate", searchDate)
			}
				
		}
	}
	
	def searchVoucherForDashboard(){
		def result = Voucher.createCriteria().list {
			order("startDate", "desc")
			maxResults(5)
		}
		return result
	}
}
